package com.example.VolunteerBank.controller;

import com.example.VolunteerBank.pojo.Result;
import com.example.VolunteerBank.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
public class FileUploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws IOException {
        log.info("文件上传，文件名：{}", file.getOriginalFilename());

        String url = aliOSSUtils.upload(file);
        log.info("文件上传完成，文件访问的url：{}", url);

        return Result.success(url);
    }

}